package com.smart.test.spring_el;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther a123
 * @create 2018-08-20 16:26
 * @desc 测试springEl 动态语言
 */
public class SpelHello {

    public static void main(String[] args){
        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression("4 + 5");
        int message = (Integer) exp.getValue();
        System.out.println(message);

        class Simple{
            public List<Boolean> booleanList = new ArrayList<Boolean>();
        }

        Simple simple = new Simple();
        simple.booleanList.add(true);

        EvaluationContext simpleContent = new StandardEvaluationContext(simple);
        parser.parseExpression("booleanList[0]").setValue(simpleContent, "false");

        System.out.println(simple.booleanList.get(0));
    }
}
